



$(function(){
	/*删除员工*/
	// console.log($('.delete-staff').length)
    
	$(document).on('click','.delete-staff',function(){
    	console.log(this);
    	alert('dskffs');
    	fadeModal('.confirm-modal');
    })
	$('.btn-add').on('click',function(){
    	fadeModal('.add-modal');
    })

    $('.born-date').fdatepicker();

    $('.add-staff').on('click',function(){
    	// console.log(validateDep());
    	if(validateStaff() != undefined){
    		fillStaff('修改成功',
			validateStaff().staffName,
			validateStaff().sex,
			validateStaff().age,
			validateStaff().phone,
			validateStaff().born,
			validateStaff().title,
			validateStaff().job)
    	}
    	//$('.add-modal').fadeOut();
    });

    /*导入员工（excel）*/

	$('.btn-import').on('click',function(){
    	fadeModal('.import-modal');
    })


	$('.btn-confirm').on('click',function(){

		var filename = document.getElementById('filename').value;

		if(filename=='' || filename==undefined || filename==null){
			setAlert('请选择文件');
			
		}
		else{
			$('.import-modal,.mask').fadeOut();
		}
	})


/*
	$('modify-info').on('click',function{
		fadeModal('.information-modal');
	})


*/    
    /*修改信息*/
	$('.modify-info').on('click',function(){
    	fadeModal('.information-modal');
    })

    $('.modify-info').on('click',function(){
    	fadeModal('.information-modal');
    })

    $('.btn-modify').on('click',function(){

    	setAlert('修改成功');
    	$('.information-modal,.mask').fadeOut();
    })

    


});


function validateStaff(){
	var staffName = $('.form-control .staffName').val(),//员工姓名
		sex = $('.sex').val(),//性别
		age = $('.age').val(),//年龄
		// depDate = $('.dep-date').val(),//创建日期
		phone = $('.phone').val(),//电话
		born = $('.born-date').val(),//出生年月
		title = $('.title').val(),//职称
		job = $('.job').val();//职位
    	if(staffName == ''){
    		setAlert('请填写员工姓名');
    	}
    	else{
    		return {
    			staffName:staffName,
    			sex:sex,
    			age:age,
    			phone:phone,
    			born:born,
    			title:title,
    			job:job
    		}
    	}
}



function fillStaff(string,staffName,title,job,age,phone){
	setAlert(string);
	$('.staff-info-name').html(staffName);
	//部门
//	$('.staff-info-dep').html(sex);
//	$('.staff-info-no').html(staffNo);
	// $('.dep-info-date').html(depDate);
	$('.staff-info-title').html(title);
	$('.staff-info-job').html(job);
	$('staff-info-age').html(age);
	$('staff-info-phone').html(phone);
	$('.add-modal,.mask').fadeOut();

}


/**文件上传获取路径**/

function changeText(th){
    var filename = document.getElementById("filename");
    var exist = th.value.lastIndexOf("\\");
    // 火狐浏览器直接可以获取到文件名
    if(exist == -1){
        filename.value = th.value;
    }
    //chrome或获取到绝对路径
    else{
        filename.value = th.value.substring(exist + 1);
    }
}

$('.file-btn').click(function(){
	$('.file-hide').click();
})

